<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends CommonController{
    public function liss(){
        $userlist = D('user')->getAll();
        $this->assign('userlist',$userlist);
        $this->display();
    }
    public function edit($id){
        $User=D('user');
        if(IS_POST){
                $_POST['addtime'] = time();
                $map['id'] =$_POST['id'];
                $pass = $User->find($_POST['id']);
                if($pass['password'] != $_POST['password']){
                    $_POST['password'] = md5($_POST['password']);
                }
                    $num = $User->where($map)->save($_POST);
                    if($num){
                        $this->success('信息修改成功！',U('user/liss'));
                    }
                    else {
                        $this->error('信息修改失败！');
                    }
        }
            else{
                $userlist = $User->find($id);
                $this->assign('list',$userlist);
                $this->display();
            }
        
    }
    public function del($id){
        $user = D('user');
        
        $num=$user->delete($id);
        if($num){
            $this->success('信息删除成功！',U('user/liss'));
        }
        else {
            $this->error('信息删除失败！');
        }
    }
}
